/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sysmap.calcci;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author Marcos Junqueira - marcos.junqueira at sysmap.com.br
 */
public class CalcBean {

    private CalculadoraSimples calc = new CalculadoraSimples();
    private Double n1;
    private Double n2;
    private Double result;

    /** Creates a new instance of CalcBean */
    public CalcBean() {
    }

    public String somar() {
        result = (Double) calc.soma( n1, n2 );
        return null;
    }

    public String subtrair() {
        result = (Double) calc.subtrai( n1, n2 );
        return null;
    }

    public String multiplicar() {
        result = (Double) calc.multiplica( n1, n2 );
        return null;
    }

    public String dividir() {
        try {
            result = (Double) calc.divide( n1, n2 );
        } catch ( DivisaoPorZeroException ex ) {
            FacesContext.getCurrentInstance().addMessage( "DivisaoPorZeroException", new FacesMessage( FacesMessage.SEVERITY_WARN, "Divisão por zero.", "Divisão por zero." ) );
            Logger.getLogger( CalcBean.class.getName() ).log( Level.SEVERE, null, ex );
        }
        return null;
    }

    public Double getN1() {
        return n1;
    }

    public void setN1( Double n1 ) {
        this.n1 = n1;
    }

    public Double getN2() {
        return n2;
    }

    public void setN2( Double n2 ) {
        this.n2 = n2;
    }

    public Double getResult() {
        return result;
    }

    public void setResult( Double result ) {
        this.result = result;
    }
}
